package com.candy.candyproduct.config;

import com.alibaba.cloud.nacos.ribbon.NacosRule;
import com.candy.candyproduct.config.weightBalance.WeightBalanceConfig;
import com.netflix.loadbalancer.IRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * Fox
 */
@Configuration
@RibbonClients(defaultConfiguration = RibbonConfig.class)
public class RibbonConfig {

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    // 自定义负载均衡策略
    @Bean
    public IRule getRule() {
//        return new WeightBalanceConfig();
        return new NacosRule();
    }

}
